/******************************************
@Description:risk风控-新增会员统计
交换机=bus.memberadd
@Time : 2020/11/13 16:10
@Author :lixiaojun
*******************************************/
package main

import (
	"context"
	"git.900sui.cn/kc/base/utils"
	"git.900sui.cn/kc/kcgin"
	"git.900sui.cn/kc/kcgin/logs"
	"git.900sui.cn/kc/rabbitmq"
	"git.900sui.cn/kc/rpcinterface/client/risk"
	"github.com/streadway/amqp"
	"strconv"
)

func main() {
	rpcBusBasicMonth := new(risk.BusBasicMonth).Init()
	defer rpcBusBasicMonth.Close()
	rpcBusBasicIndusAvg := new(risk.BusBasicIndusAvg).Init()
	defer rpcBusBasicIndusAvg.Close()

	rpcbbaa := new(risk.BusBasicAccumulative).Init()
	defer rpcbbaa.Close()

	logs.Info("Environment Variable:MSF_ENV:", kcgin.KcConfig.RunMode)
	new(utils.KcLog).GetInstance(kcgin.AppConfig.String("risk.log.riskStatisticsAddMember"))
	err := rabbitmq.Rabbitmq.Consume(kcgin.AppConfig.String("risk.queue.riskStatisticsAddMember"), func(msg amqp.Delivery) {
		memberId, _ := strconv.Atoi(string(msg.Body))
		var res bool
		if err := rpcBusBasicMonth.AddMemberNumRpc(context.Background(), &memberId, &res); err != nil {
			utils.Logerr.Printf("统计企业每月新增会员任务错误 memberId:%d error:%s\n", memberId, err.Error())
		}
		if err := rpcBusBasicIndusAvg.RiskForAddMember(context.Background(), &memberId, &res); err != nil {
			utils.Logerr.Printf("统计行业新增会员任务错误 memberId:%d error:%s\n", memberId, err.Error())
		}

		// 添加 预付卡风险管理系统-会员总人数
		if  err := rpcbbaa.UserNumRpc(context.Background(),&memberId,&res);err != nil {
			logs.Error("添加 预付卡风险管理系统-会员总人数 ，失败信息：\n", memberId, err.Error())
			return
		}

		utils.Logerr.Printf("统计新增会员任务成功 memberId:%d", memberId)
	})

	if err != nil {
		utils.Logerr.Printf("统计新增会员任务失败 err: %s\n", err.Error())
	}
}
